﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RibbonEditor.AppCode
{
    class UIActionHelper
    {
        public static string[] UndeletableItems = new string[] { "RibbonDiffXml", "CustomActions", "Templates", "CommandDefinitions", "CommandUIDefinition", "RuleDefinitions", "EnableRules", "DisplayRules", "TabDisplayRules", "Actions", "LocLabels" };

        public static void Delete(TreeNode nodeToDelete)
        {
            TreeNode parentNode = nodeToDelete.Parent;

            // Suppression de l'élément dans le parent
            if (parentNode.Tag is IChildDeletable)
            {
                ((IChildDeletable)parentNode.Tag).DeleteChild(nodeToDelete.Tag);
            }

            // Suppression du noeud du treeview
            nodeToDelete.Remove();
        }

        public static bool CanBeDeleted(string nodeText)
        {
            bool returnValue = !UndeletableItems.Contains(nodeText);
            return returnValue;
        }
    }
}
